home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / text / showtext.06 / showtext / showtext-0.06 / getword.c next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  1.7 KB  |  74 lines

  1.  
  2. /*
  3.     Copyright (C) 1995  Rolf Jakob <rjakob@duffy1.franken.de>
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. /* get a word */
  25.  
  26. char *getword(char *buffer,char *word)
  27. {
  28. char *p,*s;
  29. char sep;
  30. char *separray=" \t=\n,:;";
  31.  
  32.     *word=0;
  33.     p=buffer;
  34.     /*
  35.     while (*p && (*p==' ' || *p=='\t' || *p=='=' || *p=='\n' || *p==',')) p++;
  36.     */
  37.     while (*p && strchr(separray,*p)) p++;
  38.     if (*p==0) return(NULL);
  39.     s=p;
  40.     if (*p=='\'' || *p=='\"')
  41.     {
  42.         sep=*(p++);
  43.         while (*p && *p!=sep) p++;
  44.         strncpy(word,s+1,p-s-1);
  45.         word[p-s-1]=0;
  46.         if (!(*p)) return(NULL);
  47.         return(p+1);
  48.     }
  49.     else
  50.     {
  51.         /*
  52.         while (*p && *p!=' ' && *p!='\t' && *p!='=' && *p!='\n' && *p!=',') p++;
  53.         */
  54.         while (*p && !(strchr(separray,*p))) p++;
  55.         strncpy(word,s,p-s);
  56.         word[p-s]=0;
  57.         if (!(*p)) return(NULL);
  58.         return(p+1);
  59.     }
  60. }
  61.  
  62. /* get the last word */
  63.  
  64. char *getlastword(char *buffer, char *word)
  65. {
  66. char *p;
  67. char hword[512];
  68.  
  69.     p=getword(buffer,word);
  70.     while(p && *word) { strcpy(hword,word); p=getword(p,word); }
  71.     if (!*word) strcpy(word,hword);
  72.     return(word);
  73. }
  74.